//  理想视觉体重
import MeasureItem from './MeasureItem'
import Calc from './Calc'
//import DateUtils from '../utils/DateUtils'
const UI = require('./UI');

var isAdd = false;
export default class MuscleControlReport {
  /**
   * 肌肉控制
   *
   * float[] values = new float[4];//脂肪重量,体重控制，脂肪控制，肌肉控制
   * String[] strings = new String[4];
   * <p>
   * // 体重 > 标准体重； 体脂率 > 标准脂肪
   * if (userWeight > standWeight && userBodyFat > standFat + 1) {
   * values[0] = NumberUtils.getOnePrecision(userWeight * userBodyFat / 100);
   * values[2] = NumberUtils.getOnePrecision((userBodyFat - standFat) / 100 * userWeight);
   * values[3] = NumberUtils.getOnePrecision(values[2] * 1 / 3);
   * values[1] = NumberUtils.getOnePrecision(values[2] - values[3]);
   */
  static getStand(measure) {
    let weightControl;
    if (measure.gender == 0) {
      weightControl = ((measure.height * 1.37) - 110) * 0.45;
    } else {
      weightControl = (measure.height - 80) * 0.7;
    }

    return weightControl;
  }

  static calcFfm(measure) {

    let muscleControl;
    let standWeight = MuscleControlReport.getStand(measure);
    let userWeight = measure.weight;
    let userBodyFat = measure.bodyfat;
    let d = 1;

    let standFat = MuscleControlReport.getStandFat(measure);

    if (userWeight > standWeight && userBodyFat > standFat + 1) {

      let fatControl = ((userBodyFat - standFat) / 100 * userWeight).toFixed(2);
      muscleControl = (fatControl * 1 / 3).toFixed(2);
     
    } else if (userWeight < standWeight - d && userBodyFat < standFat) {

      let weightControl = (standWeight - userWeight).toFixed(2);
      muscleControl = (weightControl * 2 / 3).toFixed(2);

    } else { //无需控制
      muscleControl = 0;
    }
    return muscleControl;
  }

  static getStandFat(measure) {
    //在深度评估报告中最理想脂肪修改成：男性15%，⼥女性22%
    let standFat;
    if (measure == 1) {
      standFat = 15;
    } else
      standFat = 22;
    return standFat;

  }

  static isEnable(measure) {
    return true
  }

  static build(measure) {

    const value = MuscleControlReport.calcFfm(measure);
    let desc = '';
    const unit = "kg";
    const item = new MeasureItem();
    const standBmr = MuscleControlReport.calcFfm(measure);
    const boundaries = [standBmr];
    let level = Calc.calcLevel(value, boundaries, 1);
    let isStand = level == 1;

    desc = "根据健康的肌肉控制方式，建议您当前需要增加" + value + unit + "肌肉";


    if (value == 0) {
      desc = "根据健康的肌肉控制方式，您维持当前肌肉控制即可。";
    }
    if (value != 0) {
      level = 0;
      isStand = false;

    } else {
      level = 1;
      isStand = true;
    }

    item.name = "肌肉控制";
    item.value = value;
    item.isStand = isStand;
    item.unit = unit;
    item.levelNames = ['改善','标准'];
    item.bar = [UI.color.report_no_stand, UI.color.report_stand];
    item.showBar = false;
    item.desc = desc;
    item.level = level;
    item.levelName = item.levelNames[item.level]
    item.levelColor = item.bar[item.level]

    if (!isStand) {
      let offset = 0;
      if (level < standBmr) {
        offset = value - boundaries[standBmr - 1]
      } else {
        offset = value - boundaries[standBmr]
      }
      item.offset = offset
    }

    return item
  }

}



// WEBPACK FOOTER //
// ./src/report/MuscleControl.js
